﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.PmiScale.CApPMIScaleEnabler
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Collections.ObjectModel;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.PmiScale;

public class CApPMIScaleEnabler : ITxCommandEnabler
{
  protected bool _considerMode;
  protected TxPmiTextDisplayMode _mode;

  public CApPMIScaleEnabler()
  {
  }

  public CApPMIScaleEnabler(TxPmiTextDisplayMode mode)
  {
    this._considerMode = true;
    this._mode = mode;
  }

  private bool CheckEnable()
  {
    bool flag1 = false;
    bool flag2 = true;
    TxObjectList allItems = TxApplication.ActiveSelection.GetAllItems();
    if (((Collection<ITxObject>) allItems).Count == 1)
    {
      if (((Collection<ITxObject>) allItems)[0] is TxPhysicalRoot)
      {
        flag1 = true;
        flag2 = false;
      }
      else if (((Collection<ITxObject>) allItems)[0] is TxPmi txPmi)
      {
        if (txPmi.HasTextPolylines && (!this._considerMode || txPmi.TextDisplayMode == this._mode))
          flag1 = true;
        flag2 = false;
      }
    }
    if (flag2)
    {
      foreach (ITxObject itxObject in (Collection<ITxObject>) allItems)
      {
        switch (itxObject)
        {
          case TxPmi _:
          case ITxComponent _:
          case TxCompoundPart _:
          case TxCompoundResource _:
          case TxKinematicLink _:
          case TxGroup _:
            flag1 = true;
            goto label_16;
          default:
            continue;
        }
      }
    }
label_16:
    return flag1;
  }

  public bool Enable => this.CheckEnable();
}
